package com.xmqian.app.project.ui.user.activity

import android.graphics.Color
import android.text.Editable
import android.text.TextWatcher
import android.widget.Button
import android.widget.EditText
import android.widget.LinearLayout
import com.coszero.common.base.mvp.BaseMvpActivity
import com.coszero.ui.widget.CountDownTextView
import com.example.xmqian.R
import com.example.xmqian.databinding.ActivityForgetPwdBinding
import com.xmqian.app.project.ui.user.contract.ForgetPwdContract
import com.xmqian.app.project.ui.user.presenter.ForgetPwdPresenter

/**
 * @author xmqian
 * @date 2019/5/18 12:17
 * @desc 忘记密码
 */
class ForgetPwdActivity : BaseMvpActivity<ForgetPwdPresenter?>(), ForgetPwdContract.View,
    TextWatcher {
    var etUser: EditText? = null
    var etSmsCode: EditText? = null
    var tvGetCode: CountDownTextView? = null
    var btnNext: Button? = null

    private var mSmsCode: String? = null
    private var mPhone: String? = null
    private var binding: ActivityForgetPwdBinding? = null

    override fun getLayoutView(): LinearLayout {
        binding = ActivityForgetPwdBinding.inflate(layoutInflater)
        return binding!!.root
    }

    override fun initView() {
        title = resources.getString(R.string.title_forget_pwd)
        etUser = binding!!.etUser
        etSmsCode = binding!!.etSmsCode
        tvGetCode = binding!!.tvGetCode
        btnNext = binding!!.btnNext

        etUser!!.addTextChangedListener(this)
        etSmsCode!!.addTextChangedListener(this)
    }

    override fun initData() {
        requestTranslucentStatusBar(Color.parseColor("#FFFFFF"), true)
    }

    override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
    }

    override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
        if (etSmsCode!!.length() >= 4 && etUser!!.length() == 11) {
            btnNext!!.isEnabled = true
        } else {
            btnNext!!.isEnabled = false
        }
    }

    override fun afterTextChanged(s: Editable) {
    }

    override fun onNetworkError() {
        hideLoadingDialog()
    }


    fun onTvGetCodeClicked() {
        /* if (etUser.length() == 11) {
            new PicCodeDialog.Builder(this)
                    .setListener(new PicCodeDialog.OnSendSmsSuccessListener() {
                        @Override
                        public void onSuccess(Dialog dialog) {
                            dialog.dismiss();
                            tvGetCode.startCountDown(59);
                        }
                    })
                    .setType(PicCodeDialog.Builder.TYPE_RESET)
                    .setPhoneNum(etUser.getText().toString())
                    .build().show();
        } else {
            ToastHelper.getInstance().showWarn("请填写正确的手机号码");
        }*/
    }

    fun onBtnNextClicked() {
        mSmsCode = etSmsCode!!.text.toString()
        mPhone = etUser!!.text.toString()
        mPresenter!!.forgetnew1(mPhone, mSmsCode)
    }

    override fun getPresenter(): ForgetPwdPresenter {
        return ForgetPwdPresenter(this)
    }
}
